const http = require("http");
const path = require("path");
const fs = require("fs");

http.createServer((req,res)=>{
    if (req.url=="/"){
        var filePath =path.join(__dirname,"test.html");
        var fileContent = fs.readFileSync(filePath);
        res.writeHead(200,{"Content-Type":"text/html"});
        res.write(fileContent);
        res.end();
    }
    else if(req.url =="/getdata"){
        var arr =[
            {username:"zhangsan",age:20},
            {username:"lisi",age:15}
        ];
        var jsonstr = JSON.stringify(arr);
        res.writeHead(200,{"Content-Type":"text/plain"});
        res.write(jsonstr);
        res.end();
    }
   
}).listen(8083);

console.log("server is listening 8083");